package Page.TeacherAndStudentPage;

import Navigation.NavigationController;
import Dao.PartTimeTeacherDao;
import DataClass.PartTimeTeacher;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PartTimeTeacherPage {
    public static Scene getScene() {
        StackPane partTimeTeacherMenuPane = new StackPane();
        Label label = new Label("Part-time Menu Page");

        // 创建表格
        TableView<PartTimeTeacher> tableView =  new TableView<>();

        // 创建列
        TableColumn<PartTimeTeacher,String> nameColumn = new TableColumn<>("姓名");
        nameColumn.setCellValueFactory(new PropertyValueFactory<PartTimeTeacher,String>("TCName"));

        TableColumn<PartTimeTeacher,String> titleColumn = new TableColumn<>("职称");
        titleColumn.setCellValueFactory(new PropertyValueFactory<PartTimeTeacher,String>("JTNo"));

        TableColumn<PartTimeTeacher,String> professionalAffiliationsColumn = new TableColumn<>("工作单位");
        professionalAffiliationsColumn.setCellValueFactory(new PropertyValueFactory<PartTimeTeacher,String>("TProfessionalAffiliations"));

        // 填充列表
        List<TableColumn<PartTimeTeacher, ?>> columns = new ArrayList<>();
        columns.add(nameColumn);
        columns.add(titleColumn);
        columns.add(professionalAffiliationsColumn);
        tableView.getColumns().addAll(columns);

        // 装入数据
        try {
            List<PartTimeTeacher> data = PartTimeTeacherDao.getPartTimeTeacher();
            tableView.getItems().addAll(data);
        }catch (SQLException ignored)
        {
            System.err.println("数据库出现错误");
        }

        partTimeTeacherMenuPane.getChildren().add(label);
        partTimeTeacherMenuPane.getChildren().add(tableView);

        VBox vbox = new VBox();
        Button button = new Button("返回");
        button.setOnAction(event -> {
            NavigationController.back();
        });
        vbox.getChildren().add(button);
        vbox.getChildren().add(partTimeTeacherMenuPane);
        return new Scene(vbox);
    }
}
